package com.syedu.day03;

import java.time.LocalDate;
import java.util.Scanner;

/**
 * description：Java分支语句,switch case
 *
 * 1.switch括号中的条件类型只能是byte[Byte],short[Short],int[Integer],char[Character],枚举,String(JDK7.0开始)
 * 2.case值满足时,会执行对应的代码,然后如果没有遇到break,则代码会一直向下运行,直到遇到break或者程序运行结束
 * 3.如果case没有一个条件是满足的,则运行default代码,default代码不一定在switch最后,即可以写在任何位置
 * 4.JDK14开始提供了switch新版语法
 *
 * @author Administrator
 * @date 2022/3/8 9:36
 */
public class SwitchDemo {
    public static void main(String[] args) {
        LocalDate localDate = LocalDate.now();
        int week = localDate.getDayOfWeek().getValue();
        switch (week) {
            case 1:
                System.out.println("星期一");
                break;
            case 2:
                System.out.println("星期二");
                break;
            case 3:
                System.out.println("星期三");
                break;
            case 4:
                System.out.println("星期四");
                break;
            case 5:
                System.out.println("星期五");
                break;
            case 6:
                System.out.println("星期六");
                break;
            default:
                System.out.println("星期天");
        }

        System.out.println("----------------------------------");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请您输入年份和月份:");
        int year = scanner.nextInt();
        int month = scanner.nextInt();
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                System.out.println(31);
                break;//中断switch
            case 4:
            case 6:
            case 9:
            case 11:
                System.out.println(30);
                break;
            default:
                System.out.println(LocalDate.of(year, month, 1).isLeapYear() ? 29 : 28);

                //JDK14开始支持
           /* case 1, 3, 5, 7, 8, 10, 13 -> System.out.println(31);
            case 4, 6, 9, 11 -> System.out.println(30);
            default -> System.out.println(LocalDate.of(year, month, 1).isLeapYear() ? 29 : 28);*/
        }
    }
}